/*
 * EventDispatcher.h
 *
 *  Created on: May 8, 2011
 *      Author: michael
 */

#ifndef EVENTDISPATCHER_H_
#define EVENTDISPATCHER_H_

#include "Event.h"
#include <queue>
#include <vector>

namespace DerbyServ
{

class MainManager;

class EventDispatcher
{
public:
	EventDispatcher();
	virtual ~EventDispatcher();

	void Next(MainManager & mgr);
	void AddEvent(TimeEventPtr timeEvent);
	void AddEvent(StateEventPtr stateEvent);

private:
	typedef std::priority_queue< TimeEventPtr, std::vector< TimeEventPtr >, TimeEventComparisonPredicate> TimeEvents;
	typedef std::set<StateEventPtr> StateEvents;
	//typedef std::priority_queue<EventPtr, std::vector< EventPtr >, EventComparisonPredicate> Events;
	typedef std::set<EventPtr> Events;

	TimeEvents _timeEvents; // occur at a specified time
	StateEvents _stateEvents; // occur when a particular condition is met
	Events _currentEvents; // events to process now

	boost::mutex _eventsMutex;
};

typedef boost::shared_ptr<EventDispatcher> EventDispatcherPtr;

}

#endif /* EVENTDISPATCHER_H_ */
